//
//  MPTLiveApplyResultView.m
//  MPTLive
//
//  Created by caixun on 15/8/21.
//  Copyright (c) 2015年 Jeakin. All rights reserved.
//

#import "MPTLiveApplyResultView.h"
#import "UIColor+MPTColor.h"
#import "UIFont+MPTFont.h"


@interface MPTLiveApplyResultView ()

// 申请内测资格提示文字
@property (nonatomic, strong) UILabel *titleLab;
// 申请内测资格提示文字
@property (nonatomic, strong) UILabel *messageLab;
// 去秒拍看直播按钮
@property (nonatomic, strong) UIButton *goMPBtn;
// 返回按钮
@property (nonatomic, strong) UIButton *goBackBtn;

@end


@implementation MPTLiveApplyResultView


#pragma mark - ***************************** View Lifecycle ***********************************

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self initMainViews];
    }
    return self;
}

-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    
    if(newSuperview == nil)
    {
        [[self subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)];
        
        return ;
    }
}


#pragma mark - ******************************** Init All Views **********************************

- (void)initMainViews
{
    UIImageView *bgImgv = [[UIImageView alloc] initWithFrame:self.frame];
    
    UIImage *bgImg = nil;
    if(iPhone4)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_4_2"];
    }
    else if(iPhone5)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_5_2"];
    }
    else if(iPhone6)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6_2"];
    }
    else if(iPhone6p)
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6p_2"];
    }
    else
    {
        bgImg = [UIImage imageNamed:@"ApplyViewBg_6p_2"];
        bgImgv.contentMode = UIViewContentModeScaleAspectFit;
    }
    bgImgv.image = bgImg;
    [self addSubview:bgImgv];
    
    
    // 看直播去秒拍
    CGRect goMPRect = CGRectMake(20,
                                 screenH-30-44,
                                 screenW-20*2,
                                 44);
    self.goMPBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.goMPBtn.frame = goMPRect;
    [self.goMPBtn setTitle:@"看直播去秒拍" forState:UIControlStateNormal];
    [self.goMPBtn setBackgroundColor:[UIColor YXColorWithHexCode:@"#ffe200"]];
    [self.goMPBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    self.goMPBtn.layer.cornerRadius = 22;
    self.goMPBtn.titleLabel.font = [UIFont YXFontOfSize:16.0f];
    [self addSubview:self.goMPBtn];
    
    // 申请内测资格提示文字
    CGRect messageRect = CGRectMake(10,
                                    self.goMPBtn.frame.origin.y-70,
                                    screenW-10*2,
                                    50);
    self.messageLab = [[UILabel alloc] initWithFrame:messageRect];
    self.messageLab.text = @"已收到您的申请，我们会通过新浪微博私信的形式通知您的审核结果，请耐心等待。";
    self.messageLab.enabled = NO;
    self.messageLab.font = [UIFont YXFontOfSize:16.0f];
    self.messageLab.textAlignment = NSTextAlignmentCenter;
    self.messageLab.numberOfLines = 2;
    self.messageLab.textColor = [UIColor whiteColor];
    self.messageLab.backgroundColor = [UIColor clearColor];
    [self addSubview:self.messageLab];
    
    // 申请内测资格提示文字
    CGRect titleRect = CGRectMake(10,self.messageLab.frame.origin.y-30,screenW-10*2,30);
    self.titleLab = [[UILabel alloc] initWithFrame:titleRect];
    self.titleLab.text = @"已收到您的申请";
    self.titleLab.font = [UIFont YXFontOfSize:22.0f];
    self.titleLab.textAlignment = NSTextAlignmentCenter;
    self.titleLab.textColor = [UIColor whiteColor];
    self.titleLab.backgroundColor = [UIColor clearColor];
    [self addSubview:self.titleLab];
    
    // 返回按钮
    UIImage *close = [UIImage imageNamed:@"LiveOverClose"];
    UIImage *closePress = [UIImage imageNamed:@"LiveOverClosePress"];
    CGRect closeRect = CGRectMake(0, 0, 60, 60);
    self.goBackBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.goBackBtn.frame = closeRect;
    [self.goBackBtn setImage:close forState:UIControlStateNormal];
    [self.goBackBtn setImage:closePress forState:UIControlStateHighlighted];
    [self addSubview:self.goBackBtn];
}


#pragma mark - ****************************** Functions *********************************

- (void)setTargetForBtn:(id)target
         withGoMPAction:(SEL)goMPAction
       withGoBackAction:(SEL)goBackAction
{
    [self.goMPBtn addTarget:target action:goMPAction forControlEvents:UIControlEventTouchUpInside];
    [self.goBackBtn addTarget:target action:goBackAction forControlEvents:UIControlEventTouchUpInside];
}

@end
